package com.rich.widget.span

import android.graphics.Canvas
import android.graphics.Paint

/**
 * 描边文字的具体实现.
 */
class StrokeFontSpan : FontSpan() {

    /** 描边画笔  */
    private val mStrokePaint = Paint()

    /**
     * 描边颜色
     */
    var textStrokeColor = 0

    /**
     * 描边尺寸
     */
    var textStrokeSize = 0

    /**
     * 重载此函数实现具体的绘制内容.
     */
    override fun onDraw(
        canvas: Canvas,
        paint: Paint,
        text: CharSequence,
        start: Int,
        end: Int,
        x: Float,
        top: Int,
        y: Int,
        bottom: Int
    ) {
        mStrokePaint.set(paint)
        // 设置抗锯齿
        mStrokePaint.isAntiAlias = true
        // 设置防抖动
        mStrokePaint.isDither = true
        mStrokePaint.textSize = paint.textSize
        // 描边宽度
        mStrokePaint.strokeWidth = textStrokeSize.toFloat()
        mStrokePaint.style = Paint.Style.STROKE
        // 设置粗体
        //mStrokePaint.setFakeBoldText(true);
        mStrokePaint.color = textStrokeColor
        canvas.drawText(text, start, end, x, y.toFloat(), mStrokePaint)
    }

}